package com.ziyia.edittext;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {
    private EditText editText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = findViewById(R.id.btn_three);
        editText = findViewById(R.id.et_one);

//         文本改变事件
        editText.addTextChangedListener(new TextWatcher() {
            private String mBefore;
            private int mCursor;

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                mBefore = s.toString();
                mCursor = start;
                Log.d("修改之前的内容", s.toString());
                Log.d("修改之前内容的长度", Integer.valueOf(start).toString());
                Log.d("字符串中将被修改字符串的长度  ", Integer.valueOf(count).toString());
                Log.d("新增内容的长度", Integer.valueOf(after).toString());
//                editText.setText(s.toString());
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                Log.d("s", s.toString());
//                Log.d("start", Integer.valueOf(start).toString());
//                Log.d("before", Integer.valueOf(before).toString());
//                Log.d("count", Integer.valueOf(count).toString());
            }

            @Override
            public void afterTextChanged(Editable s) {
                Log.d("text_after = ", editText.getText().toString());
//                if (s.toString().contains(" ")) {
//                    editText.removeTextChangedListener(this);
//                    editText.setText(mBefore);
//                    editText.addTextChangedListener(this);
//                    editText.setSelection(mCursor);
//                }
            }
        });

//         点击事件
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(getClass().getName(), "年少有为");
            }
        });
        // 长按事件
        button.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Log.d("长按事件", "长按");
                return false;
            }
        });

        // 触摸事件
        button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.d("触摸事件", String.valueOf(event.getAction()));
                return false;
            }
        });


    }
}